using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common ;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace Colorprj
{
    public partial class frmrptPrdWiseStck : Form
    {
        public frmrptPrdWiseStck()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            //challanNo = Convert.ToInt32(textBox1.Text);
            showReport(26);
        }


        private void showReport(object productId)
        {

            ReportDocument cryRpt = new Report.rptPrdWiseStck();

            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            ParameterField paramField4 = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue4 = new ParameterDiscreteValue();


            //Set instances for input parameter 1 -  @vDepartment
            paramField.Name = "@productid";
            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue.Value = productId;
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);

            paramField4.Name = "cName";

            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue4.Value = Globalclass.CompanyName;
            paramField4.CurrentValues.Add(paramDiscreteValue4);
            //Add the paramField to paramFields
            paramFields.Add(paramField4);

            crystalReportViewer1.ParameterFieldInfo = paramFields;
            cryRpt.DataSourceConnections[0].SetConnection(Globalclass.DsnName, Globalclass.DbName, "atul", "vikas");
            cryRpt.SetDatabaseLogon("atul", "vikas", Globalclass.DsnName, Globalclass.DbName, false);


            // Microsoft.Practices.EnterpriseLibrary.Data.Database  db = DatabaseFactory.CreateDatabase();
            //string sqlCommand = "GetProductWiseStock";
           
            //DbCommand creditCommand = db.GetStoredProcCommand(sqlCommand);
            //  db.AddInParameter(creditCommand, "productid", DbType.Int32, 83);
            //DataSet UserDataSet = db.ExecuteDataSet(creditCommand);

            cryRpt.Database.Tables[0].Location = Globalclass.DsnName + ".dbo." + cryRpt.Database.Tables[0].Name; ;






            crystalReportViewer1.ReportSource = cryRpt;
           
        }

        private void tsbtnShow_Click(object sender, EventArgs e)
        {
            showReport(null);
        }

        private void frmrptPrdWiseStck_Load(object sender, EventArgs e)
        {
            Colorprj.Masters.SubProductManager spm = new Colorprj.Masters.SubProductManager();
            tsCboProduct.ComboBox.DataSource = spm.GetAllOnlyProducts().Tables[0];
            tsCboProduct.ComboBox.DisplayMember = "ProductName";
            tsCboProduct.ComboBox.ValueMember = "ProductId";
        }

        private void showToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showReport(tsCboProduct.ComboBox.SelectedValue);
        }

        private void showAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showReport(null);
        }

        private void tsCboProduct_SelectedIndexChanged(object sender, EventArgs e)
        {
            //showReport(tsCboProduct.ComboBox.SelectedValue);
        }

        //private void crystalReportViewer1_ReportRefresh(object source, CrystalDecisions.Windows.Forms.ViewerEventArgs e)
        //{
        //    showReport(null);
        //}

        //private void tsCboProduct_Click(object sender, EventArgs e)
        //{

        //}
    }
}